package com.itheima.sc.web.sms;

import com.itheima.sc.pojo.sms.HomeNewProduct;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.sms.SmsHomeNewProductService;
import com.itheima.sc.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {


    @Autowired
    private SmsHomeNewProductService newProductService;


    //添加新鲜好物的数据
    @PostMapping("/create")
    public Result addNewProduct(@RequestBody List<HomeNewProduct> newProducts){
        newProductService.addNewProduct(newProducts);
        return Result.success(null);
    }
    //批量新鲜好物
    @PostMapping("/delete")
    public Result deleteNewProduct(@RequestParam List<Long> ids){
        newProductService.deleteNewProducts(ids);
        return Result.success(null);
    }
    //分页查询新鲜好物
    @GetMapping("/list")
    public Result selectNewProductList(@RequestParam Map<String,String> param){
        PageResult pageResult=newProductService.selectNewProductList(param);
        return Result.success(pageResult);
    }
    //批量修改首页推荐的新鲜好物的状态
    @PostMapping("/update/recommendStatus")
    public Result updateNewProductStatus(@RequestParam List<Long> ids,@RequestParam("recommendStatus") Integer status){
        newProductService.updateNewProductStatus(ids,status);
        return Result.success(null);
    }
    //修改推荐好物排序
    @PostMapping("/update/sort/{id}")
    public Result updateNewProductSort(@PathVariable Long id,Integer sort){
        newProductService.updateNewProductSort(id,sort);
        return Result.success(null);
    }

}
